home *** CD-ROM | disk | FTP | other *** search
Text File | 1995-04-23 | 8.7 KB | 283 lines | [TEXT/MPCC] |
- //----------------------------------------------------------------------------------------
- // DragAndDrop protocol
- //----------------------------------------------------------------------------------------
-
- #ifndef _CREDITNOWDEMO_
- #include "CPCreditNowDemo.h"
- #endif
-
- #ifndef __DRAG__
- #include <Drag.h>
- #endif
-
- #ifndef SOM_ODDragItemIterator_xh
- #include <DgItmIt.xh>
- #endif
-
- #ifndef SOM_ODDragAndDrop_xh
- #include <DragDrp.xh>
- #endif
-
- #if GENERATING68K
- #pragma segment DragDrop
- #endif
-
- //----------------------------------------------------------------------------------------
-
- ODBoolean CPCreditNowDemo::PrivValidDataOnSU( Environment* ev, ODStorageUnit *storageUnit)
- {
- HFSFlavor *valueData;
- long valueSize;
- ODBoolean validDataWasFound = kODFalse;
-
- if ( storageUnit->Exists( ev, kODPropContents, kODAppleTEXT, 0) ||
- storageUnit->Exists( ev, kODPropContents, kCreditNowDemoKind, 0) )
- {
- validDataWasFound = kODTrue;
- } else {
- if ( storageUnit->Exists(ev, kODPropContents, kODApplehfs, 0) )
- {
- storageUnit->Focus( ev, kODPropContents, kODPosUndefined, kODApplehfs, 0, kODPosUndefined );
- valueSize = storageUnit->GetSize(ev);
- valueData = (HFSFlavor *)::NewPtr(valueSize);
- if (valueData)
- {
- StorageUnitGetValue( storageUnit, ev, valueSize, (ODValue)valueData);
- if (valueData->fileType == 'TEXT')
- validDataWasFound = kODTrue;
- }
- ::DisposePtr((Ptr)valueData);
- }
- }
- return validDataWasFound;
- }
-
- //----------------------------------------------------------------------------------------
-
- void CPCreditNowDemo::FulfillPromise(Environment* ev, ODStorageUnitView *promiseSUView)
- {
- // CodeWarrior: Cmd-Click or Search:Find Definition • Explain_FulfillPromise
- EnteringMethod("\pCPCreditNowDemo::FulfillPromise");
- ODUnused(promiseSUView);
- }
-
- //----------------------------------------------------------------------------------------
-
- void CPCreditNowDemo::DropCompleted(Environment* ev, ODPart* destPart, ODDropResult dropResult)
- {
- // CodeWarrior: Cmd-Click or Search:Find Definition • Explain_DropCompleted
- EnteringMethod("\pCPCreditNowDemo::DropCompleted");
- ODUnused(destPart);
- ODUnused(dropResult);
- }
-
- //----------------------------------------------------------------------------------------
-
- ODDragResult CPCreditNowDemo::DragEnter(Environment* ev, ODDragItemIterator* dragInfo,
- ODFacet* facet, ODPoint* where)
- {
- // CodeWarrior: Cmd-Click or Search:Find Definition • Explain_DragEnter
- EnteringMethod("\pCPCreditNowDemo::DragEnter");
- ODUnused(facet);
- ODUnused(where);
-
- ODStorageUnit *dragSU;
-
- fAcceptThisDrag = kODFalse;
- fActiveFrameHilitedForDrop = kODFalse;
- for (dragSU = dragInfo->First(ev); dragSU; dragSU = dragInfo->Next(ev))
- {
- fAcceptThisDrag = fAcceptThisDrag || this->PrivValidDataOnSU( ev,dragSU );
- }
-
- return fAcceptThisDrag;
- }
-
- //----------------------------------------------------------------------------------------
-
- ODDragResult CPCreditNowDemo::DragWithin(Environment* ev, ODDragItemIterator* dragInfo,
- ODFacet* facet, ODPoint* where)
- {
- // CodeWarrior: Cmd-Click or Search:Find Definition • Explain_DragWithin
- EnteringMethod("\pCPCreditNowDemo::DragWithin");
- ODUnused(dragInfo);
- ODUnused(where);
-
- if ( fAcceptThisDrag )
- {
- CFocus myFocus(ev, facet);
-
- ODFrame* displayFrame = facet->GetFrame(ev);
- ODShape* frameShape = displayFrame->GetFrameShape(ev, kODNULL);
- ODULong attributes = fSession->GetDragAndDrop(ev)->GetDragAttributes(ev);
- DragReference theDrag = fSession->GetDragAndDrop(ev)->GetDragReference(ev);
-
- if ( (! fActiveFrameHilitedForDrop) && ((attributes & kODDragIsInSourcePart) == kODFalse) )
- {
- RgnHandle dragHiliteRgn = frameShape->GetQDRegion(ev);
- ::ShowDragHilite(theDrag, dragHiliteRgn, kODTrue);
- fActiveFrameHilitedForDrop = kODTrue;
- }
- }
-
- return fAcceptThisDrag;
- }
-
- //----------------------------------------------------------------------------------------
-
- void CPCreditNowDemo::DragLeave(Environment* ev, ODFacet* facet, ODPoint* where)
- {
- // CodeWarrior: Cmd-Click or Search:Find Definition • Explain_DragLeave
- EnteringMethod("\pCPCreditNowDemo::DragLeave");
- ODUnused(facet);
- ODUnused(where);
-
- ODULong attributes = fSession->GetDragAndDrop(ev)->GetDragAttributes(ev);
- DragReference theDrag = fSession->GetDragAndDrop(ev)->GetDragReference(ev);
- ODPoint windowWhere = facet->GetWindowFrameTransform(ev, kODNULL)->TransformPoint(ev,where);
- ODFrame* displayFrame = facet->GetFrame(ev);
-
- if( fAcceptThisDrag )
- {
- CFocus myFocus(ev, facet);
- if (fActiveFrameHilitedForDrop )
- {
- ::HideDragHilite(theDrag);
- fActiveFrameHilitedForDrop = kODFalse;
- }
- }
- }
-
- //----------------------------------------------------------------------------------------
-
- ODDropResult CPCreditNowDemo::Drop(Environment* ev, ODDragItemIterator* dropInfo,
- ODFacet* facet, ODPoint* where)
- {
- // CodeWarrior: Cmd-Click or Search:Find Definition • Explain_Drop
- EnteringMethod("\pCPCreditNowDemo::Drop");
- ODUnused(dropInfo);
- ODUnused(facet);
- ODUnused(where);
-
- ODDropResult dropResult = kODDropFail;
-
- if ( fActiveFrameHilitedForDrop )
- {
- short mouseDownModifiers;
- short mouseUpModifiers;
- Handle dropPicHandle = NULL;
- Boolean notDone = kODTrue;
-
- ODULong attributes = fSession->GetDragAndDrop(ev)->GetDragAttributes(ev);
- DragReference theDrag = fSession->GetDragAndDrop(ev)->GetDragReference(ev);
- ::GetDragModifiers(theDrag, 0L, &mouseDownModifiers, &mouseUpModifiers);
-
- if (attributes & kODDropIsMove)
- dropResult = kODDropMove;
- else
- dropResult = kODDropCopy;
-
- // make new TextEdit record
- Rect theRect;
- SetRect(&theRect, 0, 0, 0, 0);
- TEHandle tempTE = TEStyleNew(&theRect, &theRect);
- StScrpHandle stylHandle = kODNULL;
- OSErr error = noErr;
- short fileRefNum = 0;
- Size textSize = 0;
- ODPtr textData = kODNULL;
- ODPtr fileData = kODNULL;
-
- // iterate over all SU's and collect the styled text
- TRY
- for (ODStorageUnit* dropSU = dropInfo->First(ev); dropSU && notDone; dropSU = dropInfo->Next(ev))
- {
- if (dropSU->Exists(ev, kODPropContents, kODAppleTEXT, 0))
- {
- dropSU->Focus(ev, kODPropContents, kODPosUndefined, kODAppleTEXT, 0, kODPosUndefined);
- textSize = dropSU->GetSize(ev);
- textData = ODNewPtr(textSize, kDefaultHeapID);
- StorageUnitGetValue(dropSU, ev, textSize, (ODValue)textData);
-
- if (dropSU->Exists(ev, kODPropContents, kODApplestyl, 0))
- {
- dropSU->Focus(ev, kODPropContents, kODPosUndefined, kODApplestyl, 0, kODPosUndefined);
- Size stylSize = dropSU->GetSize(ev);
- stylHandle = (StScrpHandle) ODNewHandle(stylSize);
- StorageUnitGetValue(dropSU, ev, stylSize, (ODValue) ODLockHandle((ODHandle) stylHandle));
- ODUnlockHandle((ODHandle) stylHandle);
- }
- notDone = kODFalse;
- } else {
- if (dropSU->Exists(ev, kODPropContents, kODApplehfs, 0))
- {
- dropSU->Focus(ev, kODPropContents, kODPosUndefined, kODApplehfs, 0, kODPosUndefined);
- long fileSize = dropSU->GetSize(ev); // really hfsflavor size
- fileData = ODNewPtr(fileSize, kDefaultHeapID); // really hfsflavor data
- StorageUnitGetValue(dropSU, ev, fileSize, (ODValue)fileData);
-
- THROW_IF_ERROR(::FSpOpenDF((FSSpec*)&(((HFSFlavor*)fileData)->fileSpec), fsRdPerm, &fileRefNum));
- THROW_IF_ERROR(::GetEOF(fileRefNum, &textSize));
- if (textSize == 0)
- THROW(kODErrUndefined);
-
- textData = ODNewPtr(textSize, kDefaultHeapID);
-
- THROW_IF_ERROR(::SetFPos(fileRefNum,fsFromStart,0));
- THROW_IF_ERROR(::FSRead(fileRefNum,&textSize,textData));
- THROW_IF_ERROR(::FSClose(fileRefNum));
- notDone = kODFalse;
- }
- }
-
- TESetSelect(32767, 32767, tempTE);
- TEStyleInsert(textData, textSize, stylHandle, tempTE);
-
- if (textData)
- ODDisposePtr(textData);
- if (stylHandle)
- ODDisposeHandle((ODHandle) stylHandle);
- }
-
- CATCH_ALL
- if (tempTE != kODNULL)
- ::TEDispose(tempTE);
- if (fileData != kODNULL)
- ODDisposePtr(fileData);
- if (stylHandle != kODNULL)
- ODDisposeHandle((ODHandle) stylHandle);
- if (fileRefNum != 0)
- ::FSClose(fileRefNum);
- dropResult = kODDropFail;
- ENDTRY
-
- if ( (dropResult == kODDropCopy) || (dropResult == kODDropMove) )
- {
- // OK, we got the styled text and we're now moving that into a Str255
- Size textSize = (**tempTE).teLength;
- ODPtr textData = ODNewPtr(textSize, kDefaultHeapID);
- if (! textData)
- {
- DebugStr("\pNewPtr error");
- ::TEDispose(tempTE);
- return kODDropFail ;
- }
-
- // In reality, you would preserve the style information
- if (textSize)
- {
- Size maxSize = 255 - sizeof("\p by PartMaker");
- textSize = (textSize > maxSize) ? maxSize : textSize;
- ODBlockMove(*(**tempTE).hText, &fTextData[1], textSize);
- fTextData[0] = textSize;
- }
- ::TEDispose(tempTE);
-
- this->PrivSetDirty(ev);
- facet->Invalidate(ev, kODNULL, kODNULL);
- }
- }
- return dropResult;
- }
-
-